package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.publice.aspect.annotation.Log;
import com.example.shrio.DataScope;
import com.example.util.APIState;
import com.example.util.AjaxResult;
import com.example.util.BusinessType;
import com.example.util.Pager;
import com.example.util.page.SeachParamsUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
<#if swagger2>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
</#if>

<#if restControllerStyle>
    import org.springframework.web.bind.annotation.RestController;
<#else>
    import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
    import ${superControllerClassPackage};
</#if>
/**
* <p>
    * ${table.comment!} 前端控制器
    * </p>
*
* @author ${author}
* @since ${date}
*/
<#if restControllerStyle>
    @RestController
<#else>
    @Controller
</#if>
<#if swagger2>
    @Api(value = "${table.comment!}Controller",tags={"${table.comment!}操作接口"})
</#if>
<#--@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>/${lowerEntity}")-->
@RequestMapping("<#if executeMap.moduleName??>/${executeMap.moduleName}</#if>/${executeMap.businessName}")
<#if kotlin>
    class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
    <#if superControllerClass??>
        public class ${table.controllerName} extends ${superControllerClass} {
    <#else>
        public class ${table.controllerName} {
    </#if>
    @Autowired
    private ${table.serviceName} ${lowerServiceName};

    @Autowired
    private DataScope dataScope;


    /**
    * ${table.comment}列表
    *
    * @param json
    * @return
    */

    <#if swagger2>
        @ApiOperation(value = "${table.comment}列表", httpMethod = "POST")
    </#if>
    @PostMapping(value = "/page")
    public AjaxResult page(<#if swagger2>@ApiParam(value = "${table.comment}列表参数" , required=true) </#if> @RequestBody Pager pager) {
    Page<${entity}> page = new Page<${entity}>();
    page.setCurrent(pager.getPageNum());
    page.setSize(pager.getPageSize());
    QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
    SeachParamsUtil.loadSearchParam(pager, queryWrapper);
    dataScope.dataScope(queryWrapper);
    pager.convertPage(service.page(page, queryWrapper));
    return new AjaxResult(APIState.S00, pager);
    }

    /**
    * ${table.comment}新增
    *
    * @param json
    * @return
    */
    <#if swagger2>
        @ApiOperation(value = "${table.comment}新增", httpMethod = "POST")
    </#if>
    @Log(title = "${table.comment}", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult save(<#if swagger2>@ApiParam(value = "${table.comment}列表参数" , required=true) </#if> @RequestBody ${entity} ${lowerEntity}) {
    if (${lowerEntity}.insert()) {
    return new AjaxResult(APIState.S00, "保存成功");
    }
    return new AjaxResult(APIState.S01, "保存失败");
    }

    /**
    * ${table.comment}编辑
    *
    * @param json
    * @return
    */
    <#if swagger2>
        @ApiOperation(value = "${table.comment}编辑", httpMethod = "PUT")
    </#if>
    @Log(title = "${table.comment}", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult update(<#if swagger2>@ApiParam(value = "${table.comment}列表参数" , required=true) </#if> @RequestBody ${entity} ${lowerEntity}) {
    if (${lowerEntity}.insertOrUpdate()) {
    return new AjaxResult(APIState.S00, "保存成功");
    }
    return new AjaxResult(APIState.S01, "保存失败");
    }



    /**
    * ${table.comment}刪除
    *
    * @param ids
    * @return
    */
    <#if swagger2>
        @ApiOperation(value = "${table.comment}刪除", httpMethod = "DELETE")
    </#if>
    @Log(title = "${table.comment}", businessType = BusinessType.DELETE)
    @DeleteMapping(value = "/{ids}")
    public AjaxResult delete(<#if swagger2>@ApiParam(value = "${table.comment}列表参数" , required=true) </#if> @PathVariable Integer[] ids) {
    if (ids != null) {
    if (${lowerServiceName}.removeByIds(Arrays.asList(ids))) {
    return new AjaxResult(APIState.S00, "删除成功");
    }
    }
    return new AjaxResult(APIState.S01, "删除失败");
    }


    }
</#if>
